#!/bin/sh

OUTPUT="../output_own.dat"
HOSTS=$3

if [ -f ex02_2 ] 
then

if [ $# -lt 1 ]
then
	echo "Usage ./run.sh <number of processes> <iterations> <hostname1> <hostname2> ..."
else
	j=1
	for i in $*
	 do
		if [ $j -gt 3 ] 
		then
			HOSTS=$HOSTS','$i
		fi
		j=$(($j+1))
	done
	echo "Given Hostnames" $HOSTS
	echo "Output will be passed to " $OUTPUT 
	echo "start run"
	mpirun -host $HOSTS -np $1 ./ex02_2 $2 >> $OUTPUT
	echo "task full filled. return val " $?
fi 

else
	echo "Can't find file ex02_2. Execution aborted"
fi
